from urllib import parse
import requests

word = input('请输入百度搜索的关键字：')
params = parse.quote(word)
url = 'https://www.baidu.com/s?wd=' + params
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36 Edg/93.0.961.52'}
res = requests.get(url=url, headers=headers)
html = res.text
filename = word + '.html'
with open(filename, 'w', encoding='utf-8') as f:
    f.write(html)
    print('保存成功！')
# 拓展：unquote()方法
# 将编码后的字符串转化为普通的Unicode字符
# %E5%AD%9F%E6%99%9A%E8%88%9F-->邱文斌
